<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.yc.comm.Constant"%>
<%
request.setCharacterEncoding("utf-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String strChoosedTableId = "";
try{
	strChoosedTableId = request.getParameter("choosedTableId");
}catch(Exception e){
	strChoosedTableId = "";
}
String choosedBtsName = "";
try{
	choosedBtsName = request.getParameter("choosedBtsName");
}catch(Exception e){
	choosedBtsName = "";
}
String registBeginTime = "";
try{
	registBeginTime = request.getParameter("registBeginTime");
}catch(Exception e){
	registBeginTime = "";
}
String registEndTime = "";
try{
	registEndTime = request.getParameter("registEndTime");
}catch(Exception e){
	registEndTime = "";
}
 
%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">   
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/SearchField.js"></script> 
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	
	<script type='text/javascript' src="<%=path%>/dwr/engine.js"></script>
	<script type='text/javascript' src="<%=path%>/dwr/util.js"></script>
	<script type='text/javascript' src="<%=path%>/dwr/interface/JQueryAdminWeb.js"></script>
    <title>查询</title>  

  </head>
  
  <body> 
  	<form id="forwardForm" method="POST" >
		<input type="hidden" name="strBtsName" id="strBtsNameId" value=""/> 
		<input type="hidden" name="choosedTableId" id="choosedTableId_ID" value="<%=strChoosedTableId%>"/>
		<input type="hidden" name="choosedBtsName" id="choosedBtsName_ID" value="<%=choosedBtsName%>"/>
		<input type="hidden" name="registBeginTime" id="registBeginTimeID" value="<%=registBeginTime%>"/>
		<input type="hidden" name="registEndTime" id="registEndTimeID" value="<%=registEndTime%>"/>
	</form>
  
  	<form id="downForm" action="<%=path%>/ExportAllServlet.do"   method="POST">
		<input type="hidden" name="btsName" id="btsName_ID"/>
		<input type="hidden" name="allTable" id="allTable_ID"/>
		<input type="hidden" name="registBeginTime" id="registBeginTimeIDForEx" value="<%=registBeginTime%>"/>
		<input type="hidden" name="registEndTime" id="registEndTimeIDForEx" value="<%=registEndTime%>"/>
	</form>
  
	
	<div id="northDIV"/> 
	<div id="contentDIV" style="height:100%"/>  
	
<script type="text/javascript">	
Ext.form.Field.prototype.msgTarget = 'side'; 
Ext.onReady(function()
{
	var viewport = new Ext.Viewport({
			layout:'border',
			frame:true,
			items:[ 
				{
					region: 'center',
					contentEl: 'contentDIV',
					margins:'100 0 0 0',
					split: true,
					border: false	
				}]
		});
	
	
	var btslevelStore = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JQueryAdminWeb.getQueryTable,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    });		
	btslevelStore.load();
	
	var qType = new Ext.form.ComboBox({	   
		fieldLabel: '查询数据',
		name: 'qtable',	
		width:100,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'查询数据',
		emptyText:'查询数据',
		hiddenName:'qtable',
		triggerAction: 'all',
		//allowBlank:false,
		editable:false, 
		store: btslevelStore
	}); 

	
	var btn = new  Ext.Button({
					text:'高级',
					pressed:false,					 
					handler:showWin
				});	
		
	var qPanel = new Ext.form.FormPanel({
		region : 'north',  
		bodyStyle  : 'padding: 10px; background-color: #DFE8F6',
		//labelWidth : 130,  
		height: 80,
		minSize: 80,
		maxSize: 80,
		frame:true,
		buttonAlign:'right',
		layout:'column', 
		items:[	
			{
				columnWidth:.25,
				layout: 'form',  
				labelWidth:60,	 
				labelAlign:'right',		
				items: [
					{
						xtype:'textfield',
						fieldLabel: '查询条件',
						width:150,
						name: 'btsName'
					}]
			},{
				columnWidth:.20,
				layout: 'form',  
				labelWidth:60,	 
				labelAlign:'right',		
				items: [
					{
						xtype:'datefield',
						fieldLabel: '开始时间',
						//width:150,
						value:'<%=registBeginTime%>',
						format : "Y-m-d", 
						name: 'registBeginTime'
					} ]
			},{
				columnWidth:.20,
				layout: 'form',  
				labelWidth:60,	 
				labelAlign:'right',		
				items: [
					 {
						xtype:'datefield',
						fieldLabel: '结束时间',
						//width:150,
						value:'<%=registEndTime%>',
						format : "Y-m-d", 
						name: 'registEndTime'
					}]
			},{
				columnWidth:.20,
				layout: 'form',  
				labelWidth:60,	 
				labelAlign:'right',		
				items:[qType]
			},{
				columnWidth:.10,
				layout: 'form',  
				labelWidth:60,	 
				labelAlign:'right',		
				items:[btn]
			}
		],
		buttons :[
				{
					text : '查询',
					handler : queryCon
				},{
					text : '导出',
					handler : exportBts
				},{
					text : '一键导出',
					handler : exportAll
				}
			]
	});	
	
	function showWin(){
		queryWin.show();
	}
	
	function exportBts(){
		var form = qPanel.getForm().getValues(false);
		var btsName = form.btsName;
		var qtable = form.qtable;
		
		var allTables = document.getElementById("allTable_ID").value
		
		if(qtable == "" && allTables == "")
		{
			Ext.Msg.alert('提示',"请选择查询数据！"); 
			return;
		}
		
		if(allTables != "")
			qtable = allTables;		 
		document.getElementById("allTable_ID").value = qtable;
		document.getElementById("btsName_ID").value = btsName;
		document.getElementById("downForm").submit();
	
	}
	
	function exportAll(){		  
		document.getElementById("allTable_ID").value = "1;4;7;10;13;16;2;5;8;11;14;17;3;6;9;12;15;18;19";
		document.getElementById("btsName_ID").value = "";
		document.getElementById("downForm").submit();
	
	}
	
	var winForm = function(){
			this.BTSField = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',	
					boxLabel: '无线设备',
					inputValue:1,
					name: 'BTS'	
				};
			this.magnifierField = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '塔放',
					inputValue:2,
					name: 'magnifier'	
				};	
			this.powerboxField = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '电源柜',
					inputValue:3,
					name: 'powerbox'	
				};	
			this.storagebatteryField = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '蓄电池',
					inputValue:4,
					name: 'storagebattery'	
				};		
			this.airconditionField = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '空调',
					inputValue:5,
					name: 'aircondition'	
				};	
			this.fireextinguisher = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '灭火器',
					inputValue:6,
					name: 'fireextinguisher'	
				};		

			this.bathunder = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'B级防雷器',
					inputValue:7,
					name: 'bathunder'	
				};		
			this.envmontor = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '动环监控',
					inputValue:8,
					name: 'envmontor'	
				};	
			this.dynamo = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '发电机组',
					inputValue:9,
					name: 'dynamo'	
				};	
			this.acdcdistribution = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '交直流配电',
					inputValue:10,
					name: 'acdcdistribution'	
				};	
			this.transformer = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '变压器',
					inputValue:11,
					name: 'transformer'	
				};	
			this.transfers = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '传输',
					inputValue:12,
					name: 'transfers'	
				};
			this.mainssupply = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '市电引入',
					inputValue:13,
					name: 'mainssupply'	
				};	
			this.antennafeeder = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '天馈',
					inputValue:14,
					name: 'antennafeeder'	
				};		
			this.irontower = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '铁塔',
					inputValue:15,
					name: 'irontower'	
				};	
			this.machineroom = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '机房',
					inputValue:16,
					name: 'machineroom'	
				};	
			this.powersupply = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '基础供电',
					inputValue:17,
					name: 'powersupply'	
				};	
			this.trafficinfo = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '交通状况',
					inputValue:18,
					name: 'trafficinfo'	
				};
			this.eninfo = {
					xtype : 'checkbox', 
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '地理环境',
					inputValue:19,
					name: 'geographicalenv'	
				};	
			
			winForm.superclass.constructor.call(this, {
					bodyStyle : 'padding:5px 5px 0',
					frame : true,
					id: 'winForm',
					labelAlign: 'left',
					labelWidth:0, 
					columns: 3,
					layout: 'column',
					vertical: true,
					items : [
							{
								columnWidth:.33,
								layout: 'form',   
								items:[this.eninfo,this.BTSField,this.storagebatteryField,this.bathunder,this.acdcdistribution,this.mainssupply,this.machineroom]
							}	
							,{
								columnWidth:.33,
								layout: 'form',   
								items:[this.magnifierField,this.airconditionField,this.envmontor,this.transformer,this.antennafeeder,this.powersupply]
							},
							{
								columnWidth:.33,
								layout: 'form',   	 
								items:[this.powerboxField,this.fireextinguisher,this.dynamo,this.transfers,this.irontower,this.trafficinfo]
							}
							],
					setValue : function(value){　　
			　　　　　　　 this.items.each(function(f){　　
			　　　　　　　　　　　  f.setValue(value);　
			　　　　　　　 });　　
		　　　 			},
					getValue : function(){　　
				　　　　　　　 var re = "";　　
				　　　　　　　 this.items.each(function(f){　　
				　　　　　　　　　　　 if(f.getValue() == true){　　
				　　　　　　　　　　　　　　　 re += f.inputValue + ";";　　
				　　　　　　　　　　　 }　　
				　　　　　　　 });　　
				　　　　　　　 return re.substr(0,re.length - 1);　　
				　　　 }		
				});	
	}	
	
	Ext.extend(winForm, Ext.form.FormPanel);
	
	var FolderWindow = function() {
		var _win = this;
		this.formPanel = new winForm();
		var _form = this.formPanel.getForm();
		FolderWindow.superclass.constructor.call(this, {
			title : '选择查询数据',
			width : 400,
			height : 250,
			resizable : true,
			plain : false,
			border : false,
			modal : true,
			autoScroll : false,
			layout : 'fit',
			closeAction : 'hide',
			items : this.formPanel,
			buttonAlign:'center',
			buttons : 
			[
				{	
					text : '全选',
					handler : function() 
					{ 
						if(this.text == '全选')
						{
							_form.setValue(true); 
							this.setText("全部取消");
							this.show();	
						}else
						{
							_form.reset();
							this.setText("全选");
							this.show();
						}
					}
				},
				{	
					text : ' 确定',
					handler : function() 
					{						 
						document.getElementById("allTable_ID").value = _form.getValue(); 
						_win.hide();						
					}
				},{
					text : '取消',
					handler : function() {
						_form.reset();
						_win.hide();
					},
					tooltip : '关闭对话框'
				}
			]	
		});
	}
	Ext.extend(FolderWindow, Ext.Window);
	var queryWin = new FolderWindow();
	
	
	function queryCon(){
					
		if (!qPanel.getForm().isValid())
			return;				
		var form = qPanel.getForm().getValues(false);
		var btsName = form.btsName;
		var qtable = form.qtable;
		var registBeginTime = form.registBeginTime;
		var registEndTime = form.registEndTime;
		 
		var allTables = document.getElementById("allTable_ID").value
		
		if(qtable == "" && allTables == "")
		{
			Ext.Msg.alert('提升',"请选择查询数据！"); 
			return;
		}
		
		if(allTables != "")
			qtable = allTables;
		 
			
		
		document.getElementById("strBtsNameId").value = btsName;
		document.getElementById("choosedBtsName_ID").value = btsName;
		document.getElementById("choosedTableId_ID").value = qtable
		
		document.getElementById("registBeginTimeID").value = registBeginTime
		document.getElementById("registEndTimeID").value = registEndTime
		document.getElementById("registBeginTimeIDForEx").value = registBeginTime
		document.getElementById("registEndTimeIDForEx").value = registEndTime
		
		ds.on('beforeload', function() 
		{
			ds.baseParams = {'<%=Constant.QUERY_TABLE%>':qtable,'btsName':btsName,'registBeginTime':registBeginTime,'registEndTime':registEndTime};
		});
		ds.load({params:{'<%=Constant.QUERY_TABLE%>':qtable,'btsName':btsName,'registBeginTime':registBeginTime,'registEndTime':registEndTime}});	 

		
	}
	
	var sm = new Ext.grid.CheckboxSelectionModel({singleSelect: true});	
	var recordType = Ext.data.Record.create([								
                			   {name: 'id', type: "string"},
                			   {name: 'name', type: "string"},
							   {name: 'num', type: "string"}, 
							   {name: 'url', type: "string"}
                	     ]);

	var cm  = new Ext.grid.ColumnModel(
			[ 
				new Ext.grid.RowNumberer(),
	            {header: "情况", width: 300, sortable: true, dataIndex: 'name',align:'left'}, 
				{header: "查询结果", width: 100, dataIndex: 'id',renderer: showDetail}					
			]
		);
	function showDetail(value, cellmeta, record, rowIndex, columnIndex, store)
	{
		var url = record.get("url");
		var num = record.get("num");
		//var btsName = document.getElementById("strBtsNameId").value;
		//return "<a href="+url+"?strBtsName="+btsName+" >"+ num + "</a>";  
		return "<input type='button' value='" + formatNum(num) + "' class='x-btn button' onclick='doForward(\"" + url + "\")'>";  
	}
	
	function formatNum(num)
	{
		if(num>=0 && num < 9)
			return "    "+num+"    ";
		else if(num>=10 && num < 99)
			return "   "+num+"   ";
		else if(num>=100 && num < 999)
			return "  "+num+"  ";	
		else if(num>=1000 && num < 9990)
			return " "+num+" ";		
		else  
			return ""+num+"";	
	}
	
	var ds = new Ext.data.Store({
        proxy: new Ext.data.DWRProxy(JQueryAdminWeb.query, true),	
        reader: new Ext.data.ListRangeReader({
            totalProperty: 'totalSize',
            id: 'id'
        }, recordType),
        sortInfo:{field:'id', direction:'ASC'}// 排序信息
    });
	
	var contentDiv = Ext.get("contentDIV");
	var sectionGrid = new Ext.grid.GridPanel({
	    	//el: 'contentDIV',	
			region : 'center',			
	        ds: ds,
	        cm: cm,
			title: '查询情况', 
			width: contentDiv.getComputedWidth(),
			height: contentDiv.getComputedHeight(), 
	        frame:true,
	        collapsible:false, 
	        enableDragDrop:false
	    });
    
	var displayPanel = new Ext.Panel({
		width    : contentDiv.getComputedWidth(),
		height   : contentDiv.getComputedHeight(),
		layout   : 'border',
		renderTo : 'contentDIV',
		items    : [
			qPanel,
			sectionGrid
		]
	});
	
	
	sectionGrid.render(); 
	
	ds.on('beforeload', function() 
	{
		ds.baseParams = {'<%=Constant.QUERY_TABLE%>':'<%=strChoosedTableId%>','btsName':'<%=choosedBtsName%>','registBeginTime':'<%=registBeginTime%>','registEndTime':'<%=registEndTime%>'};
	});
	ds.load({params:{'<%=Constant.QUERY_TABLE%>':'<%=strChoosedTableId%>','btsName':'<%=choosedBtsName%>','registBeginTime':'<%=registBeginTime%>','registEndTime':'<%=registEndTime%>'}});		
		
})	

function doForward(url)
{ 
	var objForm = document.getElementById("forwardForm");
	objForm.action = url;
	objForm.submit();
}
	
</script>	
  </body>
</html>
